#include<stdio.h>
#include "lcd.h"
#include "touch.h"
#include "bmp.h"
#include"shu_chuli.h"
#include <stdlib.h>
int main()
{
    lcd * s =chushihua();
    bmp_display(s , 0, 0,"./cs.bmp");
    diao * touch_s = malloc(sizeof(*touch_s));
    yige_dian(touch_s);
    int i,j;
    int a[4][4];
    if(touch_s->touch_diao_x >= 0 && touch_s->touch_diao_y >= 0)
    {
cxks:
        for(i = 0;i<4;i++)
        {
            for(j=0;j<4;j++)
            {
                a[i][j] = 0;
            }
        }
        sheng_suijishu(a,4,4);
        sheng_suijishu(a,4,4);
        for(i = 0;i<4;i++)
        {
            for(j=0;j<4;j++)
            {
                printf("%d\t",a[i][j]);
            }
            printf("\n");
        }
        hua_tu_shu(s,a,4,4);
    }
    while(1)
    {
        int fx = pudaun_fx();
        printf("fx = %d\n",fx);
        if(fx == 1)
        {
            shu_zuo_zuohe(a,4,4);
            sheng_suijishu(a,4,4);
            printf("----------\n");
            hua_tu_shu(s,a,4,4);
        }
        else if(fx == 2)
        {
            shu_you_youhe(a,4,4);
            sheng_suijishu(a,4,4);
            printf("----------\n");
            hua_tu_shu(s,a,4,4);
        }
        else if(fx == 3)
        {
            shu_shang_shanghe(a,4,4);
            sheng_suijishu(a,4,4);
            printf("----------\n");
            hua_tu_shu(s,a,4,4);
        }
        else if(fx == 4)
        {
            shu_xia_xiahe(a,4,4);;
            sheng_suijishu(a,4,4);
            printf("----------\n");
            hua_tu_shu(s,a,4,4);
        }

        int pd = jie_shu(a,4,4);
        printf("pd = %d\n",pd);
        if(pd == 1)
        {
            bmp_display(s , 0, 0,"./chenggong.bmp");
            return 0;
        }
        if(pd == 0)
        {
            bmp_display(s , 0, 0,"./shibai.bmp");
            yige_dian(touch_s);
            if(touch_s->touch_diao_x >= 0 && touch_s->touch_diao_y >= 0)
            {
                goto cxks;
            }
        }
    }
    close_lcd(s);
    return 0;
}
